////////////////////////////////////////////////////////////
/* L70etc.cpp Script Original written by Scarface//Odin  //
 *                                                      //
 * This script can be easily edited to be              //
 * used for your server. Throughout the script        //
 * are comments on what each thing does so that      //
 * you can edit this. You can create custom         //
 * teleporting locations and menus.                //
 *                                                //
 * Originally written for use with Moon++        //
 */                                             //
/////////////////////////////////////////////////


#include "StdAfx.h"
#include "Setup.h"


// --- L70etc band members ---
#define SAMURO       23625
#define BERGRISST    23619
#define MAIKYL       23624
#define SIGNICIOUS   23626
#define THUNDERSKINS 23623
#define TARGETGROUND 48000
#define TARGETAIR    48001


/*
 * EMOTE_ONESHOT_CUSTOMSPELL01 = 402,
 * EMOTE_ONESHOT_CUSTOMSPELL02 = 403,
 * EMOTE_ONESHOT_CUSTOMSPELL03 = 404,
 * EMOTE_ONESHOT_CUSTOMSPELL04 = 405,
 * EMOTE_ONESHOT_CUSTOMSPELL05 = 406,
 * EMOTE_ONESHOT_CUSTOMSPELL06 = 407,
 */


// Spells
#define SPELLFLARE       42505
#define SPELLFIRE        42501
#define SPOTLIGHT        39312
#define SPELLEARTH       42499
#define SPELLLLIGHTNING  42510
#define SPELLLLIGHTNING2 42507
#define SPELLSTORM       42500

#define SINGERSLIGHT 42510

class SamAI : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(SamAI);
    SamAI(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      RegisterAIUpdateEvent(1000);
    }
    void OnCombatStart(Unit* mTarget){}
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){ _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); }
    void OnDespawn(){
      _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true);
      RemoveAIUpdateEvent();
    }
    void AIUpdate(){
      switch(Singerstimer){
        case 1:{
          _unit->PlaySoundToSet(11803);
          _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02);
          break;
        }
        case 19:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL05); break;
        case 30:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 65:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 70:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 84:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL06); break;
        case 112: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SINGERSLIGHT), true); break;
        case 123: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 137: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL06); break;
        case 142: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 180: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 229: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 239: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL06); break;
        case 259: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL06); break;
        case 279: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      Singerstimer++;
    }
    protected:
      uint32 Singerstimer;
      int nrspells;
};

class BerAI : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(BerAI);
    BerAI(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true);
      timer = 0;
      RegisterAIUpdateEvent(1000);
    }
    void OnCombatStart(Unit* mTarget){ RegisterAIUpdateEvent(1000); }
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){ _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); }
    void OnDespawn(){ RemoveAIUpdateEvent(); }
    void AIUpdate(){
      switch (timer){
        case 10:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 30:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 34:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 38:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 104: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 123: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 140: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPOTLIGHT), true); break;
        case 145: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 168: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 229: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 230: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL06); break;
        case 279: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      timer++;
    }
  protected:
    uint32 timer;
};

class SigAI : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(SigAI);
    SigAI(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      timer = 0;
      RegisterAIUpdateEvent(1000);
    }
    void OnCombatStart(Unit* mTarget){ RegisterAIUpdateEvent(1000); }
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){ _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); }
    void OnDespawn(){ RemoveAIUpdateEvent(); }
    void AIUpdate(){
      switch (timer){
        case 10:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 30:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 34:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 38:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 70:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 85:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 123: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 140: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 165: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPOTLIGHT), true); break;
        case 166: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 168: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 180: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 193: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 229: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL06); break;
        case 259: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 279: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      timer++;
    }
    protected:
      uint32 timer;
};

class MaiAI : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(MaiAI);
    MaiAI(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
    }
    void OnCombatStart(Unit* mTarget){ RegisterAIUpdateEvent(1000); }
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){ _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); }
    void OnDespawn(){ RemoveAIUpdateEvent(); }
    void AIUpdate(){
      switch (timer){
        case 10:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 30:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 45:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 70:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 85:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 95:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 102: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 115: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); break;
        case 123: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 165: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPOTLIGHT), true); break;
        case 192: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 203: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 229: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 279: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      timer++;
    }
  protected:
    uint32 timer;
};


class ThuAI : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(ThuAI);
    ThuAI(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      timer = 0;
      RegisterAIUpdateEvent(1000);
    }
    void OnCombatStart(Unit* mTarget){ RegisterAIUpdateEvent(1000); }
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){ _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); }
    void OnDespawn(){
      RemoveAIUpdateEvent();
      _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true);
    }
    void AIUpdate(){
      switch (timer){
        case 14:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 17:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 42:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 55:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL03); break;
        case 62:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 63:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 64:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 75:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 76:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 77:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 88:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 99:  _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 110: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 137: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 140: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 142: _unit->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_ONESHOT_CUSTOMSPELL02); break;
        case 313: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 194: _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL04); break;
        case 200:{
          _unit->Emote(EMOTE_ONESHOT_CUSTOMSPELL01); 
          _unit->SetUInt32Value(UNIT_NPC_EMOTESTATE, 401);
          break;
        }
        case 279: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      timer++;
    }
  protected:
    uint32 timer;
};



class Effectsground : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(Effectsground);
    Effectsground(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      timer = 0;
      RegisterAIUpdateEvent(1000);
    }
    void OnCombatStart(Unit* mTarget){ RegisterAIUpdateEvent(1000); }
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      timer = 0;
    }
    void OnDespawn(){ RemoveAIUpdateEvent(); }
    void AIUpdate(){
      switch (timer){
        case 2:{
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING), true);
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING2), true);
          break;
        }
        case 6:  _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLEARTH), true); break;
        case 8:  _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFIRE), true);  break;
        case 72:{
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING), true);
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING2), true);
          break;
        }
        case 76: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLEARTH), true); break;
        case 78: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFIRE), true);  break;
        case 125:{
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING), true);
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING2), true);
          break;
        }
        case 128: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLEARTH), true); break;
        case 132: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFIRE), true);  break;
        case 232:{
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING), true);
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING2), true);
          break;
        }
        case 236: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLEARTH), true); break;
        case 238: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFIRE), true);  break;
        case 245:{
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING), true);
          _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLLLIGHTNING2), true);
          break;
        }
        case 249: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLEARTH), true); break;
        case 251: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFIRE), true);  break;
        case 279: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLFLARE), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      timer++;
    }
  protected:
    uint32 timer;
};

class Effectsair : public CreatureAIScript{
  public:
    ADD_CREATURE_FACTORY_FUNCTION(Effectsair);
    Effectsair(Creature* pCreature) : CreatureAIScript(pCreature){
      _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
      _unit->GetAIInterface()->m_canMove = false;
      _unit->GetAIInterface()->disable_melee = true;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
      timer = 0;
      RegisterAIUpdateEvent(1000);
    }
    void OnCombatStart(Unit* mTarget){ RegisterAIUpdateEvent(1000); }
    void OnCombatStop(Unit *mTarget){
      _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
      _unit->GetAIInterface()->SetAIState(STATE_IDLE);
      RemoveAIUpdateEvent();
    }
    void OnDied(Unit * mKiller){ RemoveAIUpdateEvent(); }
    void OnSpawn(){
      timer = 0;
      _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
    }
    void OnDespawn(){ RemoveAIUpdateEvent(); }
    void AIUpdate(){
      switch(timer){
        case 1:   _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLSTORM), true); break;
        case 70:  _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLSTORM), true); break;
        case 123: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLSTORM), true); break;
        case 230: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLSTORM), true); break;
        case 243: _unit->CastSpell(_unit, dbcSpell.LookupEntry(SPELLSTORM), true); break;
        case 280: _unit->Despawn(1000,2000000); break;
      }
      timer++;
    }
  protected:
    uint32 timer;
};

void SetupL70etc(ScriptMgr * mgr){
  mgr->register_creature_script(SAMURO,       &SamAI::Create);
  mgr->register_creature_script(BERGRISST,    &BerAI::Create);
  mgr->register_creature_script(MAIKYL,       &MaiAI::Create);
  mgr->register_creature_script(SIGNICIOUS,   &SigAI::Create);
  mgr->register_creature_script(THUNDERSKINS, &ThuAI::Create);
  mgr->register_creature_script(TARGETGROUND, Effectsground::Create);
  mgr->register_creature_script(TARGETAIR,    Effectsair::Create);
}
